var divspan1 = document.querySelector('div>span:nth-of-type(1)')
divspan1.onclick = function () {
    window.location.href = "../index.html"
}
//请求div标题的数据
var xhr = new XMLHttpRequest()
xhr.open('get', 'http://chst.vip:1234/api/getbrandtitle')
xhr.send()
xhr.onreadystatechange = function () {
    if (xhr.status === 200 && xhr.readyState === 4) {
        var x = JSON.parse(xhr.responseText).result
        // console.log(x)
        var html = ""
        x.forEach(item => {
            html += ` <div>
           ${item.brandTitle}
           <span>▼</span>
          </div><ul><li></li></ul>`
        });
        var main = document.querySelector('main')
        main.innerHTML = html
        //获取所有的div
        var maindiv=$('main>div')
        console.log(maindiv)
        //渲染商品展示的动画
        maindiv.click(function(){
            var suoyin=$(this).index('main>div')
            maindiv.eq(suoyin).next().slideToggle(1000)
            maindiv.eq(suoyin).next().siblings('ul').css({display:'none'})
        })
        //获取所有的ul
        var mainul=document.querySelectorAll('main>ul')
        var arrmainul=[...mainul]
        // console.log(mainul)
         //请求ul内容的数据
        arrmainul.map((item,index)=>{
            var xhr2 = new XMLHttpRequest()
            xhr2.open('get', 'http://chst.vip:1234/api/getbrand?brandtitleid=' + index)
            xhr2.send()
            xhr2.onreadystatechange = function () {
                if (xhr2.status === 200 && xhr2.readyState === 4) {
                    var x2 = JSON.parse(xhr2.responseText).result
                    console.log(x2)
                    var html2=""
                    x2.forEach((item2)=>{
                     
                        html2+=`<li value=${item2.brandId} class=${item2.brandName} id=${item2.categoryId}><i>${(item2.brandId)%10}</i><p>${item2.brandName}</p><span>${item2.brandInfo}</span></li>`
                      
                    })
                    arrmainul[index].innerHTML=html2
                    //获取所有的li   书写点击事件
                    var li=document.querySelectorAll('main>ul>li')
                      console.log(li)
                      li.forEach((itemli)=>{
                          var brandtitleid=itemli.getAttribute('value')
                          var brandname=itemli.getAttribute('class')
                          var categoryid=itemli.getAttribute('id')
                          var y= itemli.getAttribute('class')
                          console.log(y)
                          itemli.onclick=function(){
                             location.href=`./12跳转页.html?brandtitleid=${brandtitleid}&brandname=${brandname}&categoryid=${categoryid}&span11=${y}`
                          }
                      })
                }
            }
        })
       
        
    }
}
//书写返回index.html功能
var fanhui=document.querySelector('header>a')
fanhui.onclick=function(){
    location.href="../index.html"
}